package com.onpositive.gamemaker.spriteeditor;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.onpositive.gamemaker.editor.GameCreatorEditorPlugin;
import com.onpositive.gamemaker.swt.SWTImageManager;

public class SpriteLabelProvider implements ILabelProvider
{

	private Image defaultIcon;
	private final EditorImageManager editorImageManager;

	public SpriteLabelProvider(EditorImageManager editorImageManager)
	{
		this.editorImageManager = editorImageManager;
	}

	@Override
	public void addListener(ILabelProviderListener listener)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public boolean isLabelProperty(Object element, String property)
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public Image getImage(Object element)
	{
		if (element instanceof SpriteDescriptor)
		{
			Image image = editorImageManager.getImage(((SpriteDescriptor) element).getId());
			if (image != null)
				return image;
		}
		if (defaultIcon == null)
		{
			defaultIcon = AbstractUIPlugin.imageDescriptorFromPlugin(GameCreatorEditorPlugin.PLUGIN_ID, "icons/file.gif").createImage();
		}
		return defaultIcon;
	}

	@Override
	public String getText(Object element)
	{
		if (element instanceof SpriteDescriptor)
		{
			return ((SpriteDescriptor) element).getFileName(); 
		}
		if (element instanceof SpriteCategory)
		{
			return ((SpriteCategory) element).getCategoryName();
		}
		return null;
	}

}
